
import java.util.Arrays;

public class MiningNobel {
    
    public static int countSlow(double[] numbers) {
        Stopwatch sw = new Stopwatch();
        int N = numbers.length;
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    for(int l = 0; l < N; l++) {
                        if((numbers[i]+numbers[j]+numbers[k]+numbers[l]) == 0) {
                            cnt++;
                        }
                    }
                }
            }
        }
        StdOut.println(sw.elapsedTime());
        return cnt;
    }

    public static int count(double[] numbers) {
        int N = numbers.length;
        Arrays.sort(numbers);
        int cnt = 0;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    int l = Arrays.binarySearch(numbers, -numbers[i] - numbers[j] - numbers[k]);
                    //if l points to a valid array placement
                    if(l >= 0) {
                        cnt++;
                    }
                }
            }
        }
        return cnt;
    }
    
    
    public static double[] readFile(String file) {
        In in = new In(file);
        int count = 0;
        String s = "";
        while(in.hasNextLine()) {
            s = s + "," + in.readLine();
            count++;
        }
        String[] k= s.split(",");
        StdOut.println(k[0]);
        double[] tal = new double[count];
        for(int j = 2; j < k.length; j+=2 ) {
            tal[j/2-1]= Double.parseDouble(k[j]);
        }
        return tal;
    }
    
    public static void main(String[] args) {
        StdOut.println(count(readFile(args[0])));
        StdOut.println(countSlow(readFile(args[0])));
     
     
    } 
}

